package com.glela.ningchongqing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import com.alibaba.fastjson.JSONObject;
import com.glela.common.util.HttpUtil;

public class 易宝直连支付测试 {
//	public final static String url = "http://api.xzhuang.com/v2/yg_platform/";
//	public final static String url = "http://api.test.xzhuang.com/yg_platform/";
	public final static String url = "http://api.dev.xzhuang.com/yg_platform/";
//	public final static String url = "http://192.168.50.120:8080/yg_platform/";
	
	public static void main(String[] args) {
		alipay();
	}
	
	public static void alipay() {
		JSONObject jo = new JSONObject();
		jo.put("orderSn", "P151298043652425113");
		jo.put("payType", "21");
		jo.put("userId", "375763");
		try {
//			String post = doPost(jo.toString(), url + "alipay/getOrderString", "application/json");
			String post = doPost(jo.toString(), url + "orderPay/goToSettleAccounts", "application/json");
			System.out.println("alipay========"+post);
		} catch (Exception e) {
			System.out.println("alipay-------------------"+e.getMessage());
		}
	}

	public static String doPost(String content,String url,String contentType) throws IOException {
		StringBuilder result = new StringBuilder();
        URL postUrl = new URL(url);  
        URLConnection con = postUrl.openConnection(); 
        con.setConnectTimeout(5000);
        con.setDoOutput(true);  
        con.setRequestProperty("Pragma", "no-cache");  
        con.setRequestProperty("Cache-Control", "no-cache"); 
        if(contentType!=null)
        {
        	con.setRequestProperty("Content-Type", contentType);  
        }
        OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());    
        out.write(new String(content.getBytes("UTF-8")));  
        out.flush();  
        out.close();  
        BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));  
        String line = "";  
        for (line = br.readLine(); line != null; line = br.readLine()) {  
        	result = result.append(line);
        }  
		return result.toString();
	}
	
}
